<?php
ob_start();
session_start();
//print_r($_SESSION);
require_once "includes/config.php";
require_once "includes/functions.php";

if(empty($_GET['sid'])) {
	header("Location:index.php?notFound");
}

$sid = $_GET['sid'];

$sqlChkStore = "SELECT * FROM tbl_seller_store WHERE seller_id='$sid'";
$rstChkStore = mysql_query($sqlChkStore) or die(mysql_error());
//echo mysql_num_rows($rstChkStore);
if(mysql_num_rows($rstChkStore)==0) {
	header("Location:index.php?store=$sid");
}

//check user session
$user = checkSession();
//print_r($user);
$userId= $user['id'];
$userName= $user['name'];
$userType= $user['type'];



$rsjobcnt=mysql_query("select count(*) as cnt from tbl_post where category_id=2 AND  posted_by=".$_GET['sid']."") or die(mysql_error());
$rowjcnt=mysql_fetch_array($rsjobcnt);
$jobcnt=$rowjcnt['cnt'];

$rsjobcnt=mysql_query("select count(*) as cnt from tbl_post where category_id=2 AND  posted_by=".$_GET['sid']."") or die(mysql_error());
$rowjcnt=mysql_fetch_array($rsjobcnt);
$jobcnt=$rowjcnt['cnt'];

$jobcnt=0;
$clscnt=0;

$rsjobcnt=mysql_query("select count(*) as cnt from tbl_post where category_id=2 AND  posted_by=".$_GET['sid']."") or die(mysql_error());
$rowjcnt=mysql_fetch_array($rsjobcnt);
$jobcnt=$rowjcnt['cnt'];

$rsclscnt=mysql_query("select count(*) as cnt from tbl_post where category_id=5 AND  posted_by=".$_GET['sid']."") or die(mysql_error());
$rowclscnt=mysql_fetch_array($rsclscnt);
$clscnt=$rowclscnt['cnt'];


 if(!empty($_GET['sid'])) { 
	 $sqlSelStore="SELECT * FROM tbl_seller_store WHERE seller_id=".$_GET['sid'];
	 //echo $sqlSelStore;
	 $rstSelStore=mysql_query($sqlSelStore) or die(mysql_error());
	 $rowSelStore=mysql_fetch_array($rstSelStore);
	 $storeId = $rowSelStore['seller_store_id'];
	 $sellerName=$rowSelStore['seller_name'];
	 $storeName=$rowSelStore['store_name'];
	 $storeDescription=$rowSelStore['store_description'];
	 $storeLogo=$rowSelStore['store_logo'];
	 $storeThumb=$rowSelStore['store_image_thumb'];
	 
	 $storeGuidelines=$rowSelStore['store_guidelines'];
	 $newsletterSettings=$rowSelStore['newsletter_settings'];
	 $store_guidelines=$rowSelStore['store_guidelines'];
	//$offerSettings=0;
	 $offer=$rowSelStore['offer'];
	 
	 
	 
	 $ss = mysql_query("select googleMapKey from tbl_settings where setting_id=1") or die(mysql_error());
	 $tbl_settings = mysql_fetch_array($ss);
	 if($tbl_settings) $googleMapKey = $tbl_settings['googleMapKey'];  else $googleMapKey='';
     
	 $user_id = $_SESSION['user_id_sess'];

	 $qry = mysql_query("select * from tbl_users where user_id=$user_id") or die(mysql_error());
		   $cnt_users=mysql_num_rows($qry);
		   if($cnt_users==1)
		   {
			$users = mysql_fetch_array($qry);
			$address_line_1 	= $users['address_line_1'];
			$address_line_2 	= $users['address_line_2'];
			$address_line_3 	= $users['address_line_3'];
			$city		= $users['city'];
			$state		= $users['state'];
			$country		= $users['country'];
			$zip		= $users['zip'];
			
			
			$business_name=$users['business_name'];
			$address_line_1=$users['address_line_1'];
				
			
			
			$address_of_user	= $address_line_1;
			if($address_line_2!='')
			 $address_of_user.=",".$address_line_2;
			if($address_line_3!='')
			 $address_of_user.=",".$address_line_2;
			if($city!='')
			 $address_of_user.=",".$city;
			if($state!='')
			 $address_of_user.=",".$state;
			
			$cqry = mysql_query("select country_name from tbl_country where country_id=$country") or die(mysql_error());
			$tbl_country = mysql_fetch_array($cqry);
			if($tbl_country)
			{
			 $address_of_user.=",".$tbl_country['country_name'];
			}
			
			if($zip!='')
			{
			 $address_of_user.=",".$zip;
			}
		     
		     
		   }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php

 echo "Swapen.com - ".ucfirst($sellerName)."'s Store";

?>
</title>
<script src="js/spry/SpryTabbedPanels.js" type="text/javascript"></script>
<link href="js/spry/SpryTabbedPanels.css" rel="stylesheet" type="text/css" />
<style type="text/css">
body{
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:12px;
background-color:#fafafa;
margin:0; padding:0;
}
.boldGrey{
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:11px;
font-weight:bold;
color:#666666;
}
/*a:link{
text-decoration:underline;
color:#0711C0
}
a:visited{
text-decoration:underline;
color:#0711C0
}
a:hover{
text-decoration:none;
color:#FF8000
}
a:active {
color:#FF8000
}
.noDecorLink:link{
text-decoration:none;
border:none;
outline:none;

}*/
.header{
background-image:url(../images/header.jpg);
}
.container{
border-collapse:collapse; border-bottom-width:thin; border-left-width:thin; border-right-width:thin; border-top-width:thin;border-bottom-color:#999999;border-top-color:#999999;border-right-color:#999999;border-left-color:#999999;
}
.contentHeader
{
font-weight:bold;text-indent:10px; color:#204AFE; background-image:url(images/grey_radiant_header.jpeg);
}
.content{
line-height:20px;
text-align:justify;
padding-left:10px;
padding-right:10px;
}
.contentForm{
line-height:20px;
text-align:justify;
}
#footer 
{
	background:#FFFFFF none repeat scroll 0 0;
	border-top:3px solid #EEEEEE;
	clear:both;
	padding:5px;
}
ul#navFooter 
{
	height:15px;
	margin:0 auto;
	text-align:center;
}
ul#navFooter li 
{
	display:inline;
	list-style-image:none;
	list-style-position:outside;
	list-style-type:none;
	margin:0 2px;
}
ul#navFooter li,
ul#navFooter li a:link,
ul#navFooter li a:active,
ul#navFooter li a:visited,
ul#navFooter li a:hover
{
	font: 11px/25px Verdana, Arial, Helvetica, sans-serif; 
	color:#999;
}
ul#navFooter li a:hover
{
	text-decoration: underline; 
	color:#609629;
}
p#copyright 
{
	-x-system-font:none;
	color:#999999;
	font-family:Verdana,Arial,Helvetica,sans-serif;
	font-size:11px;
	font-size-adjust:none;
	font-stretch:normal;
	font-style:normal;
	font-variant:normal;
	font-weight:normal;
	/*line-height:25px;*/
	margin-top:20px;
	text-align:center;
}

span#listed-in { margin:2px; font-size:10px; padding:2px; }

.fieldWidth { width:210px; padding:1px}

#err-msg { color:#FF0000; padding:10px; border:1px solid #CCC; }
#suc-msg { color:#0000CC; padding:10px; border:1px solid #CCC; }

.head-tr { 		
		background:transparent url(images/greytile.png) repeat scroll 0 0;
	}
.head-tr td { padding-bottom:5px; padding-top:5px; padding-left:2px }

.errorField {color:#FF0000; font-weight:bold; }
div#panel { border:1px solid #CCC; margin:0; padding:0; }
.boldGreyNotes{
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:11px;
color:#666666;
}
.blueContentHeader{
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:11px;
color:#FFFFFF;
background-color:#0FB6FA;
}
.greyBoldCell{
background-color:#E6E6E6;
padding-left:5px;
font-weight:bold;
}
.paddingLeftCell{
padding-left:5px;
}
</style>
<script type="text/javascript" src="js/functions.js"></script>
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=true&amp;oe=utf-8&amp;key=<?php echo $googleMapKey; ?>" type="text/javascript"></script>

<link href="includes/style.css" rel="stylesheet" type="text/css" />

</head>

<body>

<?php 
	$user = checkSession();
	$userId= $user['id'];
	$userName= $user['name'];
	$userType= $user['type'];
	//echo $_SESSION['user_type_sess'];
?>

<table width="950" border="0" align="center" bgcolor="#FFFFFF">
  <tr>
    <td height="119"><?php include_once "header1.php";?></td>
  </tr>
 <!--  <tr>
    <td>
      <table width="100%"  border="0" align="center">
        <tr>
          <td width="60%">&nbsp;</td>
          <td width="40%" align="right">><?php include("search_panel.php"); ?></td>
        </tr>
      </table></td>
  </tr> -->
 
  <tr>
    <td height="193"  class="container"><table width="100%" border="0">
      <tr>
        <td height="119" colspan="2" valign="top">
		
		<div id='panel' style="border:none;">
			<div class="fullbox2_top"></div>
			<div class="fullbox2_repeat">
		<table width="100%" border="0">
          <tr>
		  	
            <td class="contentHeader">
			<div class="sellname">
			<div style="width:100%"><!--<img src="<?php //echo $storeLogo; ?>" alt="">--><img src="<?php echo $storeThumb; ?>" alt=""></div>
			<h2><?php echo $storeName; ?></h2>
			</div>
			
			<div class="selldesc">
			<table width="100%" border="0">
				<tr>					
					<td width="100%" valign="top" style="font-size:14px; font-weight:normal;"><?php echo $storeDescription; ?></td>
				</tr>
				<tr>
				  <td colspan="2">
				  	<?php 
						if($_GET['sid']==$userId) {
						?>							
							<span style="font-weight:bold;"><a href="index.php?updstore=<?php echo $storeId; ?>">Update Store</a></span>							
						<?php } ?>
						
				  </td>				  
				 </tr>
			</table>
			
			<div style="width:100%; float:left;">
				<div class="selldesc_in" style="margin:0px 0px 0px 0px;"><br />
					<p style="color:#767676; font-size:12px; font-weight:normal; margin:5px 0px;"><?php echo $offer?></p>
					<p style="color:#d80101; font-size:12px; font-weight:normal; margin:5px 0px;">$19.99 VALUE</p>
					<p style="color:#000000; font-size:12px; font-weight:normal; margin:5px 0px;"><?php echo $store_guidelines?></p>
				</div>
				<div class="selldesc_in">
					<img src="<?php echo $storeThumb; ?>" />
				</div>
			</div>
			
			</div>
			</td>
          </tr>
        </table>
			</div>
			<div class="fullbox2_bot"></div>
		</div>
		</td>
      </tr>
	  
	   <tr>
        <td height="119" colspan="2" valign="top">
		
		<div id='panel' style="border:none;">
			<div class="fullbox2_top"></div>
			<div class="fullbox2_repeat">
				<div class="fulldiv" style="text-align:center;">
					Featured Store Products
				</div>
			</div>
			<div class="fullbox2_bot"></div>
		</div>
		</td>
      </tr>
	  
	  
	   <tr>
        <td colspan="2" valign="top">
		
		<div id='panel' style="border:none;">
			<a href="javascript:history.back();"><img src="images/arrow_back.png" style="border:none; margin:0px 5px 0px 0px;" />Back to Search Results</a>
		</div>
		</td>
      </tr>
	  
	  
      <tr>
        <td height="16" colspan="2" valign="top">&nbsp;</td>
        </tr>
      <tr>
	  	<td>
		<div style="width: 950px; float: left; vertical-align: top;">
		
		<div class="mypg_left_out">
		<table style="width:100%">
		<?php
		 if($userType=='3' || $userType=='5')
		 {
		 ?>
		<tr>
			<td>
				<div class="fulldiv">
					<p style="color:#000000; font-size: 12px; font-weight: normal;">
					<?php echo $business_name ?><br />
					<?php echo $address_line_1 ?><br />
					</p>
				</div>
			</td>
		</tr>
		<?
		 }
		 ?>
		<tr>
        	<td width="214" valign="top">
			<p style="color:#767676; font-size: 14px; font-weight: normal; margin:5px 0px 5px 0px;">
				Refine Search
			</p>
			<div class="shourtbox">
			<table width="100%" border="0">
        <?php if($offerSettings)
		{
		?>
        <tr>
            <td><table width="212"  border="0" cellpadding="0" cellspacing="0">
              <tr>
                <td></td>
              </tr>
              <tr>
                <td style=" background-image:url(images/LHS_menu_top.jpg); height:10px"></td>
              </tr>
              <tr>
                <td height="30" style=" background-image:url(images/LHS_gradient_bg.jpg); background-repeat:repeat-y;height:100px; vertical-align:top;"><div id="category-title">Offer from <?php echo $sellerName; ?> </div>
                    <br />
                  <div id="category-content"><?php echo $offer; ?></div>
                  </td>
              </tr>
              <tr>
                <td style=" background-image:url(images/LHS_menu_bottom.jpg); height:18px"></td>
              </tr>
            </table></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
          </tr>
          <?php } ?>
          <tr>
            <td><table width="212"  border="0" cellpadding="0" cellspacing="0">
						  
              <tr>
                <td style="vertical-align:top;">
				<div id="category-title">Search Within Store</div>
                    <br />
                  <div class="fulldiv">
				  <center>
                    <form action="" method="post" name="formShopSearch" id="formShopSearch">
                        <input type="text" name="search_string" id="search_string" class="inputbg" style="width:120px; float:left;" />
                        <input type="submit" name="search" value="Search" class="yellow_btn" style="height:30px; margin:0px 0px 0px 10px;" />
                      </form>
                  </center>
				  </div>
				 </td>
              </tr>
			   
			  <tr>
                <td style="vertical-align:top;"><br /> <br />
				<div id="category-title">Sub-Category</div>
                    <br />
                  
                    <form action="" method="post" name="formShopSearch" id="formShopSearch">
						<select name="pro_subcategory" id="pro_subcategory" class="inputbg" onChange="getsubsearch(this.value);">
							<option value="" selected="selected">Select Sub-Category..</option>
						<?php
						$sel="";
						$sql_shocat="SELECT * FROM tbl_category where parent_id='1'";
						$rst_shocat=mysql_query($sql_shocat);
						while($row_shocat=mysql_fetch_array($rst_shocat)) {
							 $cat_id=$row_shocat['category_id'];
							 $cat_name=$row_shocat['category_name'];
							 if(isset($_GET['subcatid']))
							 {
							  echo $_GET['subcatid'];
							 if($_GET['subcatid']==$cat_id)
							  echo $sel="selected='selected'";
							  else
							   $sel="";
							 }
							 
							 echo "<option value='$cat_id' ".$sel.">$cat_name</option>";
						}
						?>
						</select>
                    </form><br /> <br />
                 
				 </td>
              </tr>
			   
			  <tr>
                <td style="vertical-align:top;">
				<div id="category-title">By Price</div>
				<p><a href="seller_store.php?sid=<?php echo $_GET['sid'] ?>&pricebtw=1">under - $10</a></p>  
				<p><a href="seller_store.php?sid=<?php echo $_GET['sid'] ?>&pricebtw=2">$10 - $50</a></p>  
				<p><a href="seller_store.php?sid=<?php echo $_GET['sid'] ?>&pricebtw=3">$50 - $100</a></p>  
				<p><a href="seller_store.php?sid=<?php echo $_GET['sid'] ?>&pricebtw=4">$100 - $500</a></p> 
				<p><a href="seller_store.php?sid=<?php echo $_GET['sid'] ?>&pricebtw=5">$500 +</a></p>           
				 </td>
              </tr>
              
            </table></td>
          </tr>
        </table>
			</div>
			</td>
		</tr>
		
		<tr>
        	<td width="214" valign="top">
			<p style="color:#767676; font-size: 14px; font-weight: normal; margin:5px 0px 5px 0px;">
				Classifieds
			</p>
			<div class="shourtbox">
			<table width="100%" border="0">
        
          	<tr>
            
                <td style="vertical-align:top;">
				<?php /*?><div id="category-title">By Price</div><?php */?>
              	<p><a href="index.php?srchPost&catId=2&posted_by=<?php echo $userId?>">Jobs - <?php echo $jobcnt?></a></p>  
				<p><a href="index.php?srchPost&catId=5&posted_by=<?php echo $userId?>">Classifieds - <?php echo $clscnt?></a></p>            
				</td>
			
          </tr>
        </table>
			</div>
			</td>
		</tr>
		
		</table>
		</div>
		
		<div class="fullbox_out">
		<table style="width:100%">
		<tr>
       		<td width="99%" height="300" style="vertical-align:top;">
			<div id='panel' style="border:none; width:700px;">
			
			<div class="fulldiv" style="width:700px;">
 			<strong class="orangehead">&nbsp;&nbsp;Product sale by <?php echo $sellerName;?></strong>
 
 	
	
	<div class="fulldiv" style="width:700px;">
	
	<div class="fulldiv" style="margin: 10px 0px 0px;">
		<?php       
	   if(!empty($_GET['sid']))
	   {
	   require_once "includes/pagination.php";
	   $itemPerPage=10;
	   $pagelink="sid=".$_GET['sid'];
		  
	   $sqlSelPro="SELECT DISTINCT tbl_items.*, tbl_product.posted_by,tbl_product.product_name,tbl_product.selling_type,tbl_product.selling_type,  tbl_product.shipping, tbl_users.user_id 
					FROM tbl_product, tbl_items, tbl_users 
					WHERE tbl_product.product_id = tbl_items.product_id AND 	 	
					 	  tbl_users.user_id=tbl_items.seller_id";
						  
	   if(!empty($_GET['pricebtw']))
	   {
		if($_GET['pricebtw']=='1')
		{
			$sqlSelPro.=" AND tbl_product.product_price < 10";		
		}
		else if($_GET['pricebtw']=='2')
		{
			$sqlSelPro.=" AND tbl_product.product_price >= 10 AND tbl_product.product_price <= 50";	
		}
		else if($_GET['pricebtw']=='3')
		{
			$sqlSelPro.=" AND tbl_product.product_price >= 50 AND tbl_product.product_price <= 100";	
		}
		else if($_GET['pricebtw']=='4')
		{
			$sqlSelPro.=" AND tbl_product.product_price >= 100 AND tbl_product.product_price <= 500";		
		}
		else if($_GET['pricebtw']=='5')
		{
			$sqlSelPro.=" AND tbl_product.product_price >500";	
		}
	   }
	   
	   if(!empty($_GET['subcatid']))
	   {
		$sqlSelPro.=" AND tbl_product.category_id IN (select category_id from tbl_category where parent_id=".$_GET['subcatid'].")";
	   }
		/*
	   if(!empty($_GET['cat']))
				$sqlSelPro.=" AND tbl_product.category_id=".$_GET['cat'];*/
	   if(!empty($_POST['search_string']))
				$sqlSelPro.=" AND tbl_product.product_name LIKE '%".$_POST['search_string']."%'";
		
		$sqlSelPro.= " AND tbl_users.user_id='$userId'";
		  
	    if(!empty($_GET['sortby'])) {
			if($_GET['sortby']=='lps') {
				$sqlSelPro .= " order by tbl_items.price ASC, tbl_product.shipping ASC";		
			}
			else if($_GET['sortby']=='hps') {
				$sqlSelPro .= " order by tbl_items.price DESC, tbl_product.shipping DESC";		
			}
			else if($_GET['sortby']=='bm') {
				$sqlSelPro .= " order by field(tbl_product.product_name, '$key') DESC";		
			}
			else if($_GET['sortby']=='online') {
				$sqlSelPro .= " order by field(tbl_product.selling_type, 'online') desc";		
			}
			else if($_GET['sortby']=='local') {
				$sqlSelPro .= " order by field(tbl_product.selling_type, 'local') desc";		
			}
			else if($_GET['sortby']=='price') {
				$sqlSelPro .= " order by tbl_product.product_price ASC";		
			} 
			 $sqlSelPro .=", tbl_items.bargain_duration DESC";	
	   } else { 
			$sqlSelPro .=" ORDER BY tbl_items.bargain_duration DESC";	
	   }
	   	//echo $sqlSelPro;					
		$rstSelPro=mysql_query(getPagingQuery($sqlSelPro,$itemPerPage));			  
		$num=mysql_num_rows($rstSelPro);
		//$num=0;
		if($num==0){
			?><div class="fulldiv">
				<div class="fullbox_top"></div>
				<div class="fullbox_repeat">
		  <?php echo "&nbsp;&nbsp;No Products Found..."; ?>
		    </div>
				<div class="fullbox_bot"></div>
			</div>
			
	    <? } else {	?>
		    
			<table align="center" width="100%" border="0">
				<tr>
					<td width="15%" style="color:#666666;">Sort Options:</td>
					<td width="15%"><a href="seller_store.php?<?php echo $pagelink; ?>&sortby=bm">Best Match</a></td>
					<?php /*?><td width="25%"><a href="seller_store.php?<?php echo $pagelink; ?>&sortby=lps">Lowest Price and Shipping</a></td>
					<td width="25%"><a href="seller_store.php?<?php echo $pagelink; ?>&sortby=hps">Highest Price and Shipping</a></td><?php */?>					
					<td width="15%"><a href="seller_store.php?<?php echo $pagelink; ?>&sortby=local">Local Only</a></td>
					<td width="15%"><a href="seller_store.php?<?php echo $pagelink; ?>&sortby=online">Online only</a></td>
					<td width="30%">
						<div class="greytab_out" style="margin:0px 5px -9px 5px;">
							<div class="greytab_left">&nbsp;</div>
							<div class="greytab_repeat" onclick="window.location='seller_store.php?sid=<?php echo $_GET['sid']?>&sortby=price'">Sort price</div>
							<div class="greytab_right">&nbsp;</div>
						</div>
					</td>
				</tr>
			</table>
	</div>
		
	</div>
	<?php
	    while($rowSelPro=mysql_fetch_array($rstSelPro))
	    {
					 
		$productId=$rowSelPro['product_id'];
		$userId=$rowSelPro['posted_by'];
		$posted_by=$rowSelPro['posted_by'];
		$shipping=$rowSelPro['shipping'];
		$itemId=$rowSelPro['item_id'];
		$productName=wordFormater($rowSelPro['product_name'],20);
		$productTitle = $rowSelPro['product_name'];
		$sellingType = $rowSelPro['selling_type'];
		if($sellingType=='both')
		     {
			    $shippingAvailability="Available";
			    $pickupAvailability="Available";
		     }
		    else if($sellingType=='online')
		     {
			    $shippingAvailability="Available";
			    $pickupAvailability="Not available";
		     }
		    else if($sellingType=='local')
		     {
			    $shippingAvailability="Not available";
			    $pickupAvailability="Available";
		     }
							
		$productPrice=number_format($rowSelPro['price'],0);
		$productCommission=number_format($rowSelPro['commission'],0);
		
		$postedDate=$rowSelPro['posted_date'];
		$sales_tax=$rowSelPro['sales_tax'];
		$bargainDate = $rowSelPro['bargain_duration'];
		$timeLeft = getRemainingTime($bargainDate);
	       
		$pimage = getProductImage($itemId,'i');
		
		if($pimage['thumb']!="") {
			     $productThumb = $pimage['thumb'];
		}  else {
			     $productThumb="images/no_image.gif";	
		}
	       //echo $timeLeft;
		if($timeLeft==0) {
			     $today=getdate();
			     //$d= mktime(0,0,0,$today['mon'],$today['day']+32,$today['year']);
			      $d = mktime(0, 0, 0, date('m'), date('d')+30, date('Y'));
			     $bargin= date('Y-m-d h:i:s',$d);
			     $sql=mysql_query("update tbl_items set bargain_duration='".$bargin."' where item_id='".$itemId."'") or mysql_error();;
			     
			     //$timeLeft = "<font color='red'>Listing Expired</font>";								
		}
		
		$qry = mysql_query("select address_line_1,user_type,address_line_2,city,state,country,zip from tbl_users where user_id=$posted_by") or die(mysql_error());
			$cnt_users=mysql_num_rows($qry);
			if($cnt_users==1)
			{
			 $users = mysql_fetch_array($qry);
			 $address_line_1 	= $users['address_line_1'];
			 $address_line_2 	= $users['address_line_2'];
			 $address_line_3 	= $users['address_line_3'];
			 $city			= $users['city'];
			 $state			= $users['state'];
			 $country		= $users['country'];
			 $zip			= $users['zip'];
			 $puser_type			= $users['user_type'];
			 
			 $address_of_seller	= $address_line_1;
			 if($address_line_2!='')
			  $address_of_seller.=",".$address_line_2;
			 if($address_line_3!='')
			  $address_of_seller.=",".$address_line_2;
			 if($city!='')
			  $address_of_seller.=",".$city;
			 if($state!='')
			  $address_of_seller.=",".$state;
			 
			 $cqry = mysql_query("select country_name from tbl_country where country_id=$country") or die(mysql_error());
			 $tbl_country = mysql_fetch_array($cqry);
			 if($tbl_country)
			 {
			  $address_of_seller.=",".$tbl_country['country_name'];
			 }
			 
			 if($zip!='')
			 {
			  $address_of_seller.=",".$zip;
			 }
			}
		
	?>
	   <input type="hidden" name="address_of_seller" value="<?php echo $address_of_seller;?>" id="address_of_seller" />
		<input type="hidden" name="address_of_user" value="<?php echo $address_of_user;?>" id="address_of_user" />
		<input type="hidden" name="lat<?php echo $productId;?>" value="" id="lat<?php echo $productId;?>" />
		<input type="hidden" name="lon<?php echo $productId;?>" value="" id="lon<?php echo $productId;?>" />
		 <script>
		   var geocoder, location1, location2, gDir;
		  var address_of_user = $('#address_of_user').val();
		  var address_of_seller = $('#address_of_seller').val();
		   geocoder = new GClientGeocoder();
			    gDir = new GDirections();
			    GEvent.addListener(gDir, "load", function() {
				    var drivingDistanceMiles = gDir.getDistance().meters / 1609.344;
				    var drivingDistanceKilometers = gDir.getDistance().meters / 1000;
				    //document.getElementById('results').innerHTML = '<strong>Address 1: </strong>' + location1.address + ' (' + location1.lat + ':' + location1.lon + ')<br /><strong>Address 2: </strong>' + location2.address + ' (' + location2.lat + ':' + location2.lon + ')<br /><strong>Driving Distance: </strong>' + drivingDistanceMiles + ' miles (or ' + drivingDistanceKilometers + ' kilometers)';
				    var result = drivingDistanceMiles.toFixed(2);
				    $('#distance').html(result+' miles <br /><span style="font-weight:bold; cursor:pointer; color:blue;" onclick="show_map(<?php echo $productId;?>,\''+address_of_seller+'\')">Show Map</span>');
			    });
		  
		  
		  
		  geocoder.getLocations(address_of_seller, function (response) {
			  if (!response || response.Status.code != 200)
			  {
				  //alert("Sorry, we were unable to geocode the first address");
			  }
			  else
			  {
				  location1 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
				  geocoder.getLocations(address_of_user, function (response) {
					  if (!response || response.Status.code != 200)
					  {
						  //alert("Sorry, we were unable to geocode the second address");
					  }
					  else
					  { 
						  location2 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
						  gDir.load('from: ' + location1.address + ' to: ' + location2.address);
					  }
					  $('#lat<?php echo $productId;?>').val(response.Placemark[0].Point.coordinates[1]);
					  $('#lon<?php echo $productId;?>').val(response.Placemark[0].Point.coordinates[0]);
				  });
			  }
		   });
		 
		  
		 </script> 
			<div class="fulldiv">
				<div class="fullbox_top"></div>
				<div class="fullbox_repeat">
					<div class="sellpro_table">
						<div class="sellpro_row1">
							<img src='<?=$productThumb?>'>
						</div>
						<div class="sellpro_row2">
							<p class="sellpro_head" style="margin:5px 0px 5px 0px;">
							<a href='index.php?products=<?=$itemId?>' class="sellpro_head" title='$productName'><?=$productName?></a>
							</p>
							<i>product owner - <?php echo getUser($userId) ?></i><br>
							<i>local pick up - <font style="color:#000000;"><?php echo $pickupAvailability?></font></i>
						</div>
						<div class="sellpro_row2" style="text-align:center;">
							<?php
							if($puser_type==3)
							{
							?>
							    <img src="images/m.png" />
							<?
							}
							?>
							<p>
								<i>miles away - </i><span id="distance"></span>
							</p>
						</div>
						<div class="sellpro_row3" style="text-align:right;">
							<p class="redtxt" style="margin:5px 0px 5px 0px;">$<?php echo $productPrice?></p>
							<p style="margin:5px 0px 5px 0px;">Shipping:<i><?php echo $shipping?></i></p>
							<p style="margin:5px 0px 5px 0px;"><a href="javascript:void(0);" onclick="return addtocart('<?php echo $itemId;?>','<?php echo $productName;?>','<?php echo $productPrice;?>','<?php echo $shipping;?>',1,'<?php echo $sales_tax;?>')"; style="font-size:14px; font-weight:bold;">ADD TO CART</a></p>
						</div>
					</div>
				</div>
				<div class="fullbox_bot"></div>
			</div>	
	<?
	    }
	?>
			<div class="fulldiv">
			<table width="100%" border="0">
         <tr>
           <td height="110">
			
		<?php		   
    	} 	
	}			
	?></td>
    </tr>
    <tr>
    <td><div align="center"><?php
				   //$pagelink="sid=".$_GET['sid'];
				   echo $disp=getPagingLink($sqlSelPro,$itemPerPage,$pagelink);							   
			 ?></div>
			</td>
         </tr>
       </table>
	   		</div>
			
			</div>
			
	   		</div>
	   		</td>
	   	</tr>
		</table>
	   	</div>
		
	   	</div>
	   	</td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="80"><?php include_once "footer.php";?></td>
  </tr>
</table>
<script>
function show_map(pid,address)
{
  // var pos = $('#more_info_link').position();
  var ntop = ( $(window).height() - $('#map_box').height() ) / 2+$(window).scrollTop();
  var nleft = ( $(window).width() - $('#map_box').width() ) / 2+$(window).scrollLeft();
  
  $('#map_box').css({'left': nleft, 'top':ntop});
  $('#map_box').show();
  var lat = $('#lat'+pid).val();
  var lon = $('#lon'+pid).val();
  initialize(lat,lon);
 
  
}
function addtocart(id,name,amt,sh,q,tax)
{
	location.href="addtocart.php?id="+id +"&name="+name+"&amt="+amt+"&shipping="+sh+"&qty=1"+"&tax="+tax;
}


function initialize(lat,lon) {
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map_canvas"));
    map.setCenter(new GLatLng(lat, lon), 13);
    var latlng = new GLatLng(lat,lon);
    map.addOverlay(new GMarker(latlng));
    
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());
  }
  
 
}
 function getsubsearch(id)
  {
	window.location="seller_store.php?sid=<?=$_GET['sid']?>&subcatid="+id;
  }
</script>
<div id="map_box" style="position:absolute; width:650px; height:470px; background:#000000; display:none;" align="center">
 <span style="float:right; color:#fff; padding:10px; font-weight:bold; cursor:pointer;" onclick="$('#map_box').hide();">x</span><br />
 <div id="map_canvas" style="width: 600px; height: 400px"></div>
</div>
</body>
</html>